package com.yunhe.control;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.yunhe.bean.Board;
import com.yunhe.bean.ShopImfor;
import com.yunhe.service.GoodsBoardService;
import com.yunhe.util.MySession;

/**
 * Servlet implementation class goodsListUpdate
 */
@WebServlet("/goodsListUpdate.do")
public class goodsListUpdate extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public goodsListUpdate() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		SqlSession se = new MySession().getSession();
		//从控制台获取请求修改的信息
		String sid = request.getParameter("goodsId");
		String sname = request.getParameter("goodsname");
		String bid = request.getParameter("boardid");
		String smoney = request.getParameter("price");
		System.out.println("sid"+ sid+"sname"+sname+"bid"+bid+"smoney"+smoney);
		//添加到shopimfor表中
		//ShopImfor b = new ShopImfor(Integer.parseInt(sid),sname,Integer.parseInt(bid),Float.parseFloat(smoney));
		ShopImfor b = new ShopImfor();
		b.setSid(Integer.parseInt(sid));
		b.setSname(sname);
		b.setBid(Integer.parseInt(bid));
		b.setSmoney(Float.parseFloat(smoney));
		boolean n= new GoodsBoardService().updateGoodsList(b);
		System.out.println(n);
		if(n == true) {
			response.sendRedirect("showGoodList.do");
			//request.getRequestDispatcher("hou/goods-list.jsp").forward(request,response);
		}else {
			response.sendRedirect("hou/goods-list-update.jsp");
		}
		
	}

}
